<?php
namespace app\console\controller;
use app\model\Banner as SelfModel;
use app\model\BannerType;

use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Request;
use think\facade\Route;
use think\facade\View;
use think\facade\Db;
use think\facade\Cache;
use think\facade\Cookie;
class Banner extends Base
{



    public function initialize()
    {
        parent::initialize();
        $this->model = "\app\model\Banner";
        $this->list_rows = 20;

        $this->order = ['type_id'=>'asc','jump_way'=>'asc','sort'=>'asc','id'=>'desc'];
    }

    public function select()
    {
        $banner_type = BannerType::where([['status', '=', 1]])->order(['sort' => 'asc', 'id' => 'desc'])->select()->toArray();
        View::assign('banner_type', $banner_type);
    }


    public function index123()
    {
//
//     $imgs = imagecreatefrompng(getcwd().'/5368.png');
//     $thumb = imagecreatefrompng(getcwd().'/qrcode_5368.png');
//     imagecopy($imgs, $thumb, 237, 589, 0, 0, 500, 500);//核心函数：复制图片资源到另一图片资源中
//     //imagecopy($imgd,$imgw,$x,$y,0,0, $wwidth,$wheight);
//     //$save="image".$dtype;
//     ////保存到服务器
//     $f_file_name = "/last.png";
//     imagepng($thumb,getcwd().$f_file_name); //保存
//     imagedestroy($thumb);

        $QR = imagecreatefromstring(file_get_contents(getcwd().'/qrcode_3622.png'));
        $logo = imagecreatefromstring(file_get_contents(getcwd().'/3622.png'));
        $QR_width = imagesx($QR);//二维码图片宽度
        $QR_height = imagesy($QR);//二维码图片高度
        $logo_width = imagesx($logo);//logo图片宽度
        $logo_height = imagesy($logo);//logo图片高度
        // logo在QR中的宽度 改成4则无法识别最终定位5
        $logo_qr_width = $QR_width / 5;
        $scale = $logo_width / $logo_qr_width;
        $logo_qr_height = $logo_height / $scale;
        $from_width = ($QR_width - $logo_qr_width) / 2;
        //重新组合图片并调整大小
        imagecopyresampled($QR, $logo, $from_width, $from_width,
            0, 0, $logo_qr_width, $logo_qr_height,
            $logo_width, $logo_height);
        //输出图片
        header("Content-type: image/png");
        ImagePng($QR);
  die;

        $image = imagecreatetruecolor(50, 50);
        $bgcolor = imagecolorallocate($image,246,78,4);
        imagefill($image,0,0,$bgcolor);
        $fontcolor = imagecolorallocate($image,255,255,255);
        $font = 15;
        $rand = mt_rand(1000,9999);
//        qrcode((string)$rand,'qrcode_'.$rand.'.png');
        imagestring($image,5,7,16,$rand,$fontcolor);
        header('Content-type:image/png');
        imagepng($image,$rand.'.png');
       // file_put_contents($rand.'.png',$image);
        die;
    }




}